<extend name="Public/base"/>

<block name="style">
    <script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>
</block>

<block name="body">
    <div class="main-title">
        <h2>{:isset($info['id'])?'编辑':'新增'}商品</h2>
    </div>
    <form action="{:U('saveGoods')}" method="post" class="form-horizontal">
        <div class="form-item">
            <label class="item-label">商品名称</label>
            <div class="controls">
                <input type="text" class="text input-large" name="goods_name" value="{$info.goods_name|default=''}">
            </div>
        </div>

        <div class="form-item">
            <label class="item-label">分类</label>
            <div class="controls">
                <select name="cate_id" id="cate">
                    <volist name="cateList" id="vo">
                        <option value="{$vo.id}" <if condition="$info['cate_id'] eq $vo['id']">selected</if>>{$vo.name}</option>
                    </volist>
                </select>
            </div>
        </div>

        <div class="form-item">
            <label class="item-label">品牌</label>
            <div class="controls">
                <select name="brand_id" id="brand">
                    <volist name="brandList" id="vo">
                        <option value="{$vo.id}" <if condition="$info['brand_id'] eq $vo['id']">selected</if>>{$vo.name}</option>
                    </volist>
                </select>
            </div>
        </div>

        <div class="form-item">
            <label class="item-label">型号</label>
            <div class="controls">
                <select name="model_id" id="model">
                    <volist name="modelList" id="vo">
                        <option value="{$vo.id}" <if condition="$info['model_id'] eq $vo['id']">selected</if>>{$vo.name}</option>
                    </volist>
                </select>
            </div>
        </div>

         <div class="form-item">
            <label class="item-label">商品等级</label>
            <div class="controls">
                <input type="text" class="text input-large" name="level" value="{$info.level|default=''}">
            </div>
        </div>

         <div class="form-item">
            <label class="item-label">等级描述</label>
            <div class="controls">
                <input type="text" class="text input-large" name="level_des" value="{$info.level_des|default=''}">
            </div>
        </div>

        <div class="form-item">
            <label class="item-label">上传图片</label>
            <div class="controls">
                <input type="file" id="upload_good_img">
                <div class="upload-img-box" id="good_img_cover">
                    <notempty name="info.good_img">
                        <volist name="info['good_img_arr']" id="vo">
                         <div class="upload-pre-item">
                                <input type="hidden" name="good_img[]" value="{$vo}"/>
                                <img src="__ROOT__{$vo}"/>
                               <a class="delete-pop" onclick="deleteimg($(this))" href="javascript:;" title="关闭"></a>
                         </div>
                        </volist>
                    </notempty>
                </div>
            </div>

            <script type="text/javascript">
                //上传图片
                /* 初始化上传插件 */
                $("#upload_good_img")
                    .uploadify(
                        {
                            "height" : 30,
                            "swf" : "__STATIC__/uploadify/uploadify.swf",
                            "fileObjName" : "download",
                            "buttonText" : "上传图片",
                            "uploader" : "{:U('File/upload',array('session_id'=>session_id()))}",
                            "width" : 100,
                            'removeTimeout' : 1,
                            'fileTypeExts' : '*.jpg; *.png; *.gif;',
                            "onUploadSuccess" : uploadPicture,
                            'onFallback' : function() {
                                alert('未检测到兼容版本的Flash.');
                            }
                        });
                function uploadPicture(file, data) {
                    var data = eval('('+data+')');
                    var src = '';
                    if (data.status) {
                        src = data.url || '__ROOT__' + data.url;
                        var imgdom='<div class="upload-pre-item">'+
                                   '<input type="hidden" name="good_img[]" value="'+data.url+'"/>'+
                                   '<img src="'+src+'"/>'+
                                   ' <a class="delete-pop" onclick="deleteimg($(this))" href="javascript:;" title="关闭"></a>'+
                                   '</div>';
                        $("#good_img_cover").append(imgdom);
                    } else {
                        layer.msg(data.info);
                    }
                }
            </script>
        </div>



        <div class="form-item">
            <input type="hidden" name="id" value="{$info.id|default=''}">
            <button class="btn submit-btn ajax-post" id="submit" type="submit" target-form="form-horizontal">确 定</button>
            <button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
        </div>
    </form>
</block>

<block name="script">
    <script type="text/javascript">
        //导航高亮
        highlight_subnav("{:U('index')}");
        $(function(){
            //商品分类切换时
             $("#cate").change(function(){        
               var cate_id = $(this).val();
               $.ajax({
                    type:'GET',
                    data:{cate_id:cate_id}, 
                    url:"{:U('admin/Goods/ajaxGetGoodBrand')}",
                    success:function(data){                            
                           $("#brand").html('')
                           $("#brand").append(data);
                    }
              }); 
             });    

            //商品品牌切换时
            $("#brand").change(function(){        
             var brand_id = $(this).val();
             $.ajax({
                    type:'GET',
                    data:{brand_id:brand_id}, 
                    url:"{:U('admin/Goods/ajaxGetGoodModel')}",
                    success:function(data){                            
                           $("#model").html('')
                           $("#model").append(data);
                    }
            });           


          });
        })

        function deleteimg(self){
            self.parent().remove();
            return false;
        }
    </script>
</block>